package com.ruoyi.web.controller.wexin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.weixin.Exception.BussnissExecption;
import com.ruoyi.weixin.anno.ILog;
import com.ruoyi.weixin.anno.RequireLogin;
import com.ruoyi.weixin.entity.*;
import com.ruoyi.weixin.service.*;
import com.ruoyi.weixin.vo.RePassvO;
import com.ruoyi.weixin.vo.UserPassWord;
import com.ruoyi.weixin.vo.UserVo;
import com.ruoyi.weixin.vo.userId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/wexinLogin/frents")
public class FrentsController {

    @Autowired
    UserService userInfoService;

    @Autowired
    ArticleService articleService;
    @Autowired
    GoodsService goodsService;

    @Autowired
    FrentsService frentsService;

    @PostMapping("/list")
    public R<?> loginCheck(@RequestBody userId pagesResultp) {
        return R.ok(frentsService.AllList(pagesResultp));
    }

    @PostMapping("/listSi")
    public R<?> listSi(@RequestBody userId userId) {
        return R.ok(frentsService.listSi(userId));
    }

    @PostMapping("/listbyid")
    public R<?> listbyid(String id,String userId) {
        return R.ok(frentsService.listbyid(id,userId));
    }

    @RequireLogin
    @ILog("去掉点赞")
    @PostMapping("/remGood")
    public R<?> remGood(String id,String frentsId) {
        return R.ok(goodsService.remove(new LambdaQueryWrapper<Goods>().eq(Goods::getUserId,id).eq(Goods::getFrentsId,frentsId)));
    }
    @ILog("点赞")
    @RequireLogin
    @PostMapping("/insertGood")
    public R<?> insertGood(@RequestBody Goods goods) {
        return R.ok(goodsService.save(goods));
    }

    @ILog("删除动态")
    @PostMapping("/delete")
    public R<?> delete(String userId,String frentId) {
        return R.ok(frentsService.delete(userId,frentId));
    }
    @RequireLogin
    @ILog("评论")
    @PostMapping("/insertArticle")
    public R<?> insertArticle(@RequestBody Article article) {
        article.setCreateTime(new Date(System.currentTimeMillis()));
        article.setType("0");
        return R.ok(articleService.save(article));
    }
}
